package com.sczmgk.hotline_pzh.view;

import com.sczmgk.hotline_pzh.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.Checkable;
import android.widget.ImageView;

/**
 * 自定义选择图片
 * @author Administrator
 *
 */
public class CustomSecectPicImageView extends ImageView implements Checkable {
	private ScaleAnimation sa;
	private boolean mCheck;

	public CustomSecectPicImageView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		initAnimation();
		
	}

	public CustomSecectPicImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initAnimation();
	}

	public CustomSecectPicImageView(Context context) {
		super(context);
		initAnimation();
	}

	
	private void initAnimation() {
	       sa = new ScaleAnimation(0.7f, 1.0f, 0.7f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
	       sa.setDuration(100);
	       sa.setFillAfter(true);
		}
	@Override
	public void setChecked(boolean checked) {
		mCheck = checked;
		if (mCheck) {
//			this.setPressed(true);
			this.setBackgroundResource(R.drawable.select_pic_selected);
			this.setAnimation(sa);
		} else {
//			this.setPressed(false);
			this.setBackgroundResource(R.drawable.select_pic_normal);
			this.clearAnimation();
		}
	}

	@Override
	public boolean isChecked() {
		return mCheck;
	}

	@Override
	public void toggle() {
		setChecked(!mCheck);
	}

}
